package com.xiaolin.structure.queue.array;

/**
 * @ClassName DemoQueueTest
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/11/7
 * @Version 1.0
 */
public class DemoQueueTest {
    public static void main(String[] args) {
        DemoQueue<Person> demoQueue=new DemoQueue<>(4);
        demoQueue.add(new Person(1));
        demoQueue.add(new Person(2));
        demoQueue.add(new Person(3));
        demoQueue.add(new Person(4));
        // 此时front==-1,rear==3
        System.out.println(demoQueue.size());
        Person r1 = demoQueue.remove();  // 此时front==0,rear==3
        Person r2 = demoQueue.remove();  // 此时front==1,rear==3
        Person r3 = demoQueue.remove();  // 此时front==2,rear==3
        Person r4 = demoQueue.remove();  // 此时front==3,rear==3
        System.out.println(r1.age);
        System.out.println(r2.age);
        System.out.println(r3.age);
        System.out.println(r4.age);
        System.out.println(demoQueue.size());
        demoQueue.add(new Person(5));  //此时front==3,rear==0
        demoQueue.remove();  //此时front==0,rear==0
        System.out.println(demoQueue.size());
        System.out.println(demoQueue.getFront().getAge());
        System.out.println(demoQueue.getRear().getAge());
    }

    /**
     * @ClassName Person
     * @Description TODO
     * @Detail detail
     * @Author MyPC
     * @Date 2020/11/7
     * @Version 1.0
     */
    public static class Person {
        private int age;
        public Person(int age){
            this.age=age;
        }

        public int getAge() {
            return age;
        }
    }
}
